﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.UI;
using DBService;
using HYFamilyLibDataManager;
using HYFamilyLibManager.FamilyLibModule;
using LampUseFactorManager;

namespace HYFamilyLibManager.ForProject
{
	public partial class DlgFamilyManagerForPro : System.Windows.Forms.Form, IDlgBase
	{
		public static DlgFamilyManagerForPro GetInstance(ExternalCommandData revit)
		{
			if (DlgFamilyManagerForPro.main == null || DlgFamilyManagerForPro.main.IsDisposed)
			{
				DlgFamilyManagerForPro.main = new DlgFamilyManagerForPro(revit);
			}
			return DlgFamilyManagerForPro.main;
		}

		public TreeView TrCategory
		{
			get
			{
				return this.TrCategory;
			}
		}

		public void WhenSubjectChange()
		{
			if (this.CurrentSubject != null)
			{
				this.searchDb = this.CurrentSubject.Database;
				this.tsmiAddFamily.Enabled = false;
				this.btnDelCategory.Enabled = false;
				this.btnAddFamily.Enabled = false;
				this.btnDelFamily.Enabled = false;
				this.btnEditFamily.Enabled = false;
				this.btnDownload.Enabled = false;
				this.btnAddType.Enabled = false;
				this.btnEditType.Enabled = false;
				this.btnDelType.Enabled = false;
				this.outputToolStripMenuItem.Enabled = true;
				this.lvFamily.ContextMenuStrip = this.cmsFamily;
				this.dgvType.DataSource = "";
				this.dgvType.ContextMenuStrip = null;
				this.toolStripStatusLabel1.Text = this.CurrentSubject.Name + "-";
			}
		}

		public void WhenCategoryChange()
		{
			if (this.CurrentCategory != null)
			{
				try
				{
					this.lvFamily.Items.Clear();
					this.lvFamily.LargeImageList.Images.Clear();
					this.lvFamily.SmallImageList.Images.Clear();
					this.btnDelCategory.Enabled = true;
					this.btnLoadToPro.Enabled = true;
					this.toolStripStatusLabel1.Text = this.CurrentSubject.Name + "-" + this.CurrentCategory.Name;
					new List<DbFamily>();
					List<DbFamily> allFamilies = this.CurrentCategory.GetAllFamilies(false, CheckType.All);
					this.lvFamily.BeginUpdate();
					foreach (DbFamily dbFamily in allFamilies)
					{
						this.lvFamily.LargeImageList.Images.Add(dbFamily.Name, dbFamily.Image);
						this.lvFamily.SmallImageList.Images.Add(dbFamily.Name, dbFamily.Image);
						ListViewItem listViewItem = new ListViewItem();
						listViewItem.Text = dbFamily.Name;
						listViewItem.Tag = dbFamily;
						listViewItem.ImageKey = dbFamily.Name;
						ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
						listViewSubItem.Text = dbFamily.Version;
						listViewItem.SubItems.Add(listViewSubItem);
						ListViewItem.ListViewSubItem listViewSubItem2 = new ListViewItem.ListViewSubItem();
						listViewSubItem2.Text = dbFamily.Date.ToString();
						listViewItem.SubItems.Add(listViewSubItem2);
						ListViewItem.ListViewSubItem listViewSubItem3 = new ListViewItem.ListViewSubItem();
						listViewSubItem3.Text = this.proDb.CategoryTable[dbFamily.ParentId].Name;
						listViewItem.SubItems.Add(listViewSubItem3);
						ListViewItem.ListViewSubItem listViewSubItem4 = new ListViewItem.ListViewSubItem();
						listViewSubItem4.Text = dbFamily.Description;
						listViewItem.SubItems.Add(listViewSubItem4);
						this.lvFamily.Items.Add(listViewItem);
					}
					this.lvFamily.EndUpdate();
					this.lvFamily.Focus();
					this.searchMode = SearchMode.Category;
					this.familyCount = this.CurrentCategory.GetFamilyCount(false, CheckType.All);
					if (this.familyCount < DlgFamilyManagerForPro.pageContainment)
					{
						this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment + 1;
					}
					else if (this.familyCount % DlgFamilyManagerForPro.pageContainment > 0)
					{
						this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment + 1;
					}
					else
					{
						this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment;
					}
					this.label2.Text = "/" + this.pageCount.ToString();
					this.cbxPageCount.Items.Clear();
					for (int i = 1; i <= this.pageCount; i++)
					{
						this.cbxPageCount.Items.Add(i);
					}
					if (this.cbxPageCount.Items.Count > 0)
					{
						this.cbxPageCount.SelectedIndex = 0;
					}
					return;
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
					return;
				}
			}
			this.btnAddFamily.Enabled = false;
			this.btnTop.Enabled = false;
			this.btnPrevious.Enabled = false;
			this.btnNext.Enabled = false;
			this.btnBottom.Enabled = false;
		}

		public void WhenFamilyChange()
		{
			if (this.CurrentCategory != null)
			{
				if (this.CurrentFamily != null)
				{
					DbCategory dbCategory = this.CurrentFamily.Database.CategoryTable[this.CurrentFamily.ParentId];
					this.searchDb = this.CurrentFamily.Database;
					DbSubject dbSubject = this.CurrentFamily.Database.SubjectTable.AllSubject()[0];
					this.btnAddType.Enabled = true;
					this.btnDelFamily.Enabled = true;
					this.btnEditFamily.Enabled = true;
					this.btnAddType.Enabled = true;
					this.btnDownload.Enabled = true;
					this.ShowType();
					if (this.CurrentCategory == null)
					{
						this.toolStripStatusLabel1.Text = dbSubject + "-" + this.CurrentFamily;
						return;
					}
					this.toolStripStatusLabel1.Text = string.Concat(new object[]
					{
						dbSubject.Name,
						"-",
						dbCategory.Name,
						"\\",
						this.CurrentFamily
					});
					return;
				}
			}
			else
			{
				this.btnAddFamily.Enabled = false;
				this.btnTop.Enabled = false;
				this.btnPrevious.Enabled = false;
				this.btnNext.Enabled = false;
				this.btnBottom.Enabled = false;
			}
		}

		public UIApplication UiApp
		{
			get
			{
				return this.m_uiApp;
			}
			set
			{
				this.m_uiApp = value;
			}
		}

		public DbSubject CurrentSubject
		{
			get
			{
				if (this.CurrentFamily != null)
				{
					DbSubject dbSubject = this.CurrentFamily.Database.SubjectTable.AllSubject()[0];
					if (this.currentSubject == null || dbSubject.Guid != this.currentSubject.Guid)
					{
						this.currentSubject = dbSubject;
						return dbSubject;
					}
				}
				return this.currentSubject;
			}
			set
			{
				this.currentSubject = value;
				this.WhenSubjectChange();
			}
		}

		public DbCategory CurrentCategory
		{
			get
			{
				if (this.CurrentFamily != null)
				{
					DbCategory dbCategory = this.CurrentFamily.Database.CategoryTable[this.CurrentFamily.ParentId];
					if (this.currentCategory == null || dbCategory.Guid != this.currentCategory.Guid)
					{
						this.currentCategory = dbCategory;
						return dbCategory;
					}
				}
				return this.currentCategory;
			}
			set
			{
				this.currentCategory = value;
				this.WhenCategoryChange();
			}
		}

		public DbFamily CurrentFamily
		{
			get
			{
				return this.currentFamily;
			}
			set
			{
				this.currentFamily = value;
				this.WhenFamilyChange();
			}
		}

		public DlgFamilyManagerForPro(ExternalCommandData revit)
		{
			this.mRvit = revit;
			this.m_uiApp = revit.Application;
			this.InitializeComponent();
		}

		private void FrmMain_Load(object sender, EventArgs e)
		{
			this.tvProject.AfterLabelEdit += this.trCategory_AfterLabelEdit;
			this.tvProject.ItemDrag += this.trFamilyTree_ItemDrag;
			this.lvFamily.ItemDrag += this.listView1_ItemDrag;
			this.lvFamily.DragEnter += this.listView1_DragEnter;
			this.lvFamily.AfterLabelEdit += this.listView1_AfterLabelEdit;
			this.tvProject.DragEnter += this.trFamilyTree_DragEnter;
			this.tvProject.DragOver += this.trFamilyTree_DragOver;
			this.tvProject.MouseClick += this.trFamilyTree_MouseClick;
			this.tvProject.DragDrop += this.trFamilyTree_DragDrop;
			this.tvProject.MouseDown += this.trFamilyTree_MouseDown;
			this.dgvType.SortCompare += this.dgvType_SortCompare;
			this.dgvType.ColumnHeaderMouseClick += this.dgvType_ColumnHeaderMouseClick;
			if (!File.Exists(ConfigUtils.GetDbConfigFileName()))
			{
				ConfigUtils.CreateFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName());
			}
			DbData dbData = ConfigUtils.ReadFamilyLibXmlFile("项目族库类型", this.m_uiApp.Application.VersionNumber);
			if (dbData is LocalDbData)
			{
				this.rbLocal.Checked = true;
			}
			else if (dbData is ServerDbData)
			{
				this.rbServer.Checked = true;
			}
			this.autoLogin();
		}

		private void dgvType_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
		}

		private void dgvType_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
		{
			e.SortResult = string.Compare(e.CellValue1.ToString(), e.CellValue2.ToString());
			if (e.SortResult == 0)
			{
				e.SortResult = ((Convert.ToDouble(this.dgvType.Rows[e.RowIndex1].Cells[e.Column.Name]) > Convert.ToDouble(this.dgvType.Rows[e.RowIndex2].Cells[e.Column.Name])) ? e.RowIndex1 : e.RowIndex2);
			}
			e.Handled = true;
		}

		private void listView1_DragEnter(object sender, DragEventArgs e)
		{
			e.Effect = DragDropEffects.Move;
		}

		private void trFamilyTree_ItemDrag(object sender, ItemDragEventArgs e)
		{
			base.DoDragDrop(e.Item, DragDropEffects.Move);
		}

		private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
		{
			this.lvFamily.DoDragDrop(this.lvFamily.SelectedItems[0], DragDropEffects.Copy | DragDropEffects.Move);
		}

		private void trFamilyTree_DragEnter(object sender, DragEventArgs e)
		{
			if (e.Data.GetDataPresent(typeof(TreeNode)))
			{
				e.Effect = DragDropEffects.Move;
				return;
			}
			if ((ListViewItem)e.Data.GetData(typeof(ListViewItem)) != null)
			{
				e.Effect = DragDropEffects.Move;
				return;
			}
			this.Cursor = Cursors.No;
		}

		private void trFamilyTree_DragOver(object sender, DragEventArgs e)
		{
			this.Cursor = Cursors.Hand;
		}

		private void trFamilyTree_DragDrop(object sender, DragEventArgs e)
		{
			this.Cursor = Cursors.Default;
            System.Drawing.Point pt = ((TreeView)sender).PointToClient(new System.Drawing.Point(e.X, e.Y));
			TreeNode nodeAt = ((TreeView)sender).GetNodeAt(pt);
			if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
			{
				TreeNode treeNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
				if (nodeAt == treeNode)
				{
					return;
				}
				TreeNode treeNode2 = this.FindRoot(treeNode);
				TreeNode treeNode3 = this.FindRoot(nodeAt);
				if (treeNode2.Text != treeNode3.Text)
				{
					MessageBox.Show("只能在同一专业下修改分类从属关系！", "族库管理");
					return;
				}
				if (!(treeNode.Tag is DbCategory) || !(nodeAt.Tag is Parent))
				{
					return;
				}
				try
				{
					Parent parent = (Parent)nodeAt.Tag;
					DbCategory dbCategory = (DbCategory)treeNode.Tag;
					if (!dbCategory.ParentId.Equals(parent.Guid) && MessageBox.Show(string.Concat(new string[]
					{
						"是否要将\"",
						dbCategory.Name,
						"\"分类移至\"",
						parent.Name,
						"\"？"
					}), "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK && dbCategory.ReParent(parent))
					{
						nodeAt.Nodes.Add(treeNode.Clone() as TreeNode);
						treeNode.Remove();
						nodeAt.ExpandAll();
					}
					return;
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
					return;
				}
			}
			if (nodeAt.Tag is DbCategory)
			{
				ListViewItem listViewItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
				Parent parent2 = (Parent)nodeAt.Tag;
				DbFamily dbFamily = (DbFamily)listViewItem.Tag;
				if (!dbFamily.Database.Equals(parent2.Database))
				{
					MessageBox.Show("只能在同一专业下修改族从属关系！", "族库管理");
					return;
				}
				Parent parent3;
				if (this.CurrentCategory == null)
				{
					parent3 = this.CurrentSubject;
				}
				else
				{
					parent3 = this.CurrentCategory;
				}
				try
				{
					if (!dbFamily.ParentId.Equals(parent2.Guid) && MessageBox.Show(string.Concat(new string[]
					{
						"是否要将\"",
						dbFamily.Name,
						"\"族移至\"",
						parent2.Name,
						"\"分类？"
					}), "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK && dbFamily.ChangeParent(parent2))
					{
						List<DbFamily> allFamilies = parent3.GetAllFamilies(true, CheckType.All);
						this.lvFamily.Items.Clear();
						this.lvFamily.LargeImageList.Images.Clear();
						this.lvFamily.SmallImageList.Images.Clear();
						this.toolStripProgressBar1.Visible = true;
						this.toolStripProgressBar1.Minimum = 0;
						this.toolStripProgressBar1.Maximum = allFamilies.Count;
						this.toolStripProgressBar1.Step = 1;
						this.toolStripProgressBar1.Value = 0;
						this.lvFamily.BeginUpdate();
						foreach (DbFamily dbFamily2 in allFamilies)
						{
							this.toolStripProgressBar1.PerformStep();
							this.lvFamily.LargeImageList.Images.Add(dbFamily2.Name, dbFamily2.Image);
							this.lvFamily.SmallImageList.Images.Add(dbFamily2.Name, dbFamily2.Image);
							ListViewItem listViewItem2 = new ListViewItem();
							listViewItem2.Text = dbFamily2.Name;
							listViewItem2.Tag = dbFamily2;
							listViewItem2.ImageKey = dbFamily2.Name;
							ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
							listViewSubItem.Text = dbFamily2.Version;
							listViewItem2.SubItems.Add(listViewSubItem);
							ListViewItem.ListViewSubItem listViewSubItem2 = new ListViewItem.ListViewSubItem();
							listViewSubItem2.Text = dbFamily2.Date.ToString();
							listViewItem2.SubItems.Add(listViewSubItem2);
							ListViewItem.ListViewSubItem listViewSubItem3 = new ListViewItem.ListViewSubItem();
							listViewSubItem3.Text = parent2.Database.CategoryTable[dbFamily2.ParentId].Name;
							listViewItem2.SubItems.Add(listViewSubItem3);
							ListViewItem.ListViewSubItem listViewSubItem4 = new ListViewItem.ListViewSubItem();
							listViewSubItem4.Text = dbFamily2.Description.ToString();
							listViewItem2.SubItems.Add(listViewSubItem4);
							this.lvFamily.Items.Add(listViewItem2);
						}
						this.lvFamily.EndUpdate();
						this.toolStripProgressBar1.Visible = false;
					}
				}
				catch (Exception ex2)
				{
					MessageBox.Show(ex2.Message);
				}
			}
		}

		private void trFamilyTree_MouseClick(object sender, MouseEventArgs e)
		{
			this.tvProject.ContextMenuStrip = null;
			TreeNode nodeAt = this.tvProject.GetNodeAt(e.X, e.Y);
			if (nodeAt.Level == 0)
			{
				this.tvProject.ContextMenuStrip = this.cmsSubject;
				return;
			}
			if (nodeAt.Tag is DbCategory)
			{
				this.tvProject.ContextMenuStrip = this.cmsCategory;
			}
		}

		private void btnAddCategory_Click(object sender, EventArgs e)
		{
			this.cmdAddProject();
		}

		private void cmdAddProject()
		{
			if (!this.IsServer)
			{
				this.doAddProject();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddFamily())
				{
					this.doAddProject();
					return;
				}
				MessageBox.Show("您的账号没有添加族的权限。");
			}
		}

		private void doAddProject()
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "Revit模型|*.rvt";
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				foreach (string text in openFileDialog.FileNames)
				{
					if (this.UiApp.ActiveUIDocument.Document.PathName == text)
					{
						MessageBox.Show("不能导入当前文档，请重新选择文档导入。");
						return;
					}
					Document document = null;
					try
					{
						document = this.UiApp.Application.OpenDocumentFile(text);
					}
					catch (Autodesk.Revit.Exceptions.OperationCanceledException)
					{
						break;
					}
                    catch (Autodesk.Revit.Exceptions.ApplicationException)
					{
						MessageBox.Show("不能打开更高版本的Revit文件。");
						break;
					}
					try
					{
						string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(document.Title);
						DbCategory dbCategory = this.proDb.CategoryTable[fileNameWithoutExtension];
						if (dbCategory != null)
						{
							if (MessageBox.Show("项目已经存在，是否覆盖？", "项目族库", MessageBoxButtons.YesNo) == DialogResult.No)
							{
								break;
							}
							this.ImportCategory(dbCategory, document);
						}
						else
						{
							dbCategory = new DbCategory(fileNameWithoutExtension);
							dbCategory.Image = new Bitmap(200, 200);
							this.proDb.SubjectTable.AllSubject()[0].AddCategory(dbCategory);
							this.ImportCategory(dbCategory, document);
						}
					}
					catch
					{
					}
					finally
					{
						if (document != this.UiApp.ActiveUIDocument.Document)
						{
							document.Close(false);
						}
					}
				}
			}
		}

		private void ImportCategory(DbCategory project, Document doc)
		{
			Dictionary<string, List<Family>> dictionary = new Dictionary<string, List<Family>>();
			RevitVersionFuncs.GetDocumentFamilies(dictionary, doc);
			List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>();
			foreach (KeyValuePair<string, List<Family>> keyValuePair in dictionary)
			{
				KeyValuePair<int, string> item = new KeyValuePair<int, string>(keyValuePair.Value.Count, keyValuePair.Key);
				list.Add(item);
			}
			ProgressForm progressForm = new ProgressForm(list, "项目族库", true);
			foreach (KeyValuePair<string, List<Family>> keyValuePair2 in dictionary)
			{
				try
				{
					string key = keyValuePair2.Key;
					DbCategory dbCategory = project[key];
					if (dbCategory == null)
					{
						dbCategory = new DbCategory(key);
						dbCategory.Image = new Bitmap(200, 200);
						project.AddCategory(dbCategory);
					}
					foreach (Family family in keyValuePair2.Value)
					{
						this.ImportFamily(dbCategory, family);
						if (!progressForm.ProgressStep(1) && progressForm.IsStoped)
						{
							MessageBox.Show("中断操作！");
							return;
						}
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
					progressForm.Dispose();
				}
			}
			progressForm.Dispose();
			List<FamilyLibDatabase> list2 = new List<FamilyLibDatabase>();
			list2.Add(this.proDb);
			FamilyLibDatabase.FillTree(this.tvProject, list2, CheckType.All);
			if (this.tvProject.Nodes[0].Nodes.Count <= 0)
			{
				this.btnLoadToPro.Enabled = false;
				return;
			}
			this.btnLoadToPro.Enabled = true;
		}

		private void ImportFamily(DbCategory category, Family family)
		{
			try
			{
				bool flag = false;
				if (category.Database.FamilyTable[family.Name] != null)
				{
					flag = true;
				}
				string tempPath = Path.GetTempPath();
				if (family.IsEditable)
				{
					Document document = this.mRvit.Application.ActiveUIDocument.Document.EditFamily(family);
					if (document.IsFamilyDocument)
					{
						FileInfo fileInfo = new FileInfo(tempPath + family.Name + ".rfa");
						if (fileInfo.Exists)
						{
							fileInfo.Delete();
						}
						RevitVersionFuncs.SaveAs(document, fileInfo.FullName);
						document.Close(false);
						try
						{
							DbFamily dbFamily = new DbFamily(family.Name, FamilyUtil.GetPreview(new Size(200, 200), family));
							dbFamily.SetDate(DateTime.Now);
							dbFamily.Version = this.mRvit.Application.Application.VersionNumber;
							dbFamily.GetTypeParams(this.mRvit.Application.ActiveUIDocument.Document, family, category);
							if (flag)
							{
								if (category.Database.FamilyTable[family.Name].Remove(false) && category.AddFamily(dbFamily, fileInfo))
								{
									dbFamily.RecordTypes(this.mRvit.Application.ActiveUIDocument.Document, category.Database, fileInfo.FullName);
								}
							}
							else if (category.AddFamily(dbFamily, fileInfo))
							{
								dbFamily.RecordTypes(this.mRvit.Application.ActiveUIDocument.Document, category.Database, fileInfo.FullName);
							}
						}
						catch
						{
						}
						finally
						{
							fileInfo.Delete();
						}
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void cmdAddCategory()
		{
			if (!this.IsServer)
			{
				this.doAddCategory();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddFamily())
				{
					this.doAddCategory();
					return;
				}
				MessageBox.Show("您的账号没有添加分类的权限。");
			}
		}

		private void doAddCategory()
		{
		}

		private void btnDelCategory_Click(object sender, EventArgs e)
		{
			if (this.tvProject.SelectedNode == null)
			{
				MessageBox.Show("请选择需删除的分类节点");
				return;
			}
			this.cmdDelCategory();
		}

		private void cmdDelCategory()
		{
			if (this.IsServer)
			{
				if (this.CurrentUser == null)
				{
					this.cmdLogin();
				}
				if (this.CurrentUser != null)
				{
					if (this.CurrentUser.CanAddFamily())
					{
						this.doDelCategory();
						this.Recount();
						this.CurrentFamily = null;
						FamilyLibDatabase.FillTree(this.tvProject, this.dbs, CheckType.All);
						if (this.tvProject.Nodes[0].Nodes.Count <= 0)
						{
							this.btnLoadToPro.Enabled = false;
							return;
						}
						this.btnLoadToPro.Enabled = true;
						return;
					}
					else
					{
						MessageBox.Show("您的账号没有删除项的权限。");
					}
				}
				return;
			}
			this.doDelCategory();
			this.Recount();
			this.CurrentFamily = null;
			FamilyLibDatabase.FillTree(this.tvProject, this.dbs, CheckType.All);
			if (this.tvProject.Nodes[0].Nodes.Count <= 0)
			{
				this.btnLoadToPro.Enabled = false;
				return;
			}
			this.btnLoadToPro.Enabled = true;
		}

		private void doDelCategory()
		{
			if (this.CurrentCategory != null && MessageBox.Show("确实要把选中项删除？", "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK)
			{
				try
				{
					if (this.CurrentCategory.Remove(false))
					{
						this.CurrentFamily = null;
						this.tvProject.Nodes.Remove(this.tvProject.SelectedNode);
					}
					else
					{
						MessageBox.Show(this.CurrentCategory.Name + "删除失败", "族库管理");
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
		}

		public TreeNode FindRoot(TreeNode node)
		{
			if (node.Parent == null)
			{
				return node;
			}
			return this.FindRoot(node.Parent);
		}

		private void btnAddFamily_Click(object sender, EventArgs e)
		{
			this.cmdAddFamily();
		}

		private void cmdAddFamily()
		{
			if (!this.IsServer)
			{
				this.doAddFamily();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddFamily())
				{
					this.doAddFamily();
					return;
				}
				MessageBox.Show("您的账号没有添加族的权限。");
			}
		}

		private void doAddFamily()
		{
		}

		private void Recount()
		{
			string name = this.CurrentSubject.Name;
			TreeNode count = null;
			foreach (object obj in this.tvProject.Nodes)
			{
				TreeNode treeNode = (TreeNode)obj;
				if (treeNode.Text.Contains(name))
				{
					count = treeNode;
					break;
				}
			}
			if (this.CurrentCategory != null)
			{
				this.setCount(count);
				return;
			}
			long num = (long)this.CurrentSubject.Database.FamilyTable.Count(CheckType.All);
			this.tvProject.SelectedNode.Text = this.CurrentSubject.ToString() + "(" + num.ToString() + ")";
			this.lvFamily.Items.Clear();
		}

		private void setCount(TreeNode tn)
		{
			if (tn.Tag is DbCategory)
			{
				tn.Text = ((DbCategory)tn.Tag).ToString();
				if (tn.Parent != null)
				{
					this.setCount(tn.Parent);
					return;
				}
			}
			else if (tn.Tag is DbSubject)
			{
				long num = (long)((DbSubject)tn.Tag).Database.FamilyTable.Count(CheckType.All);
				tn.Text = ((DbSubject)tn.Tag).ToString() + "(" + num.ToString() + ")";
				if (num == 0L)
				{
					this.lvFamily.Items.Clear();
				}
			}
		}

		private void tsmiAddCategory_Click(object sender, EventArgs e)
		{
			this.doAddCategory();
		}

		private void tsmiDelCategory_Click(object sender, EventArgs e)
		{
			this.doDelCategory();
		}

		private void tsmiAddFamily_Click(object sender, EventArgs e)
		{
			this.cmdAddFamily();
		}

		private void btnEditFamilyParam_Click(object sender, EventArgs e)
		{
			this.cmdEditFamily();
		}

		private void cmdEditFamily()
		{
			if (!this.IsServer)
			{
				this.doEditFamily();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanEditFamily())
				{
					this.doEditFamily();
					return;
				}
				MessageBox.Show("您的账号没有编辑族的权限。");
			}
		}

		private void doEditFamily()
		{
			if (!this.m_uiApp.ActiveUIDocument.Document.IsFamilyDocument)
			{
				if (this.lvFamily.SelectedItems.Count > 0)
				{
					using (DlgEditFamily instance = DlgEditFamily.GetInstance(this))
					{
						instance.Activate();
						instance.ShowDialog(this);
					}
					this.lvFamily.SelectedItems[0].Remove();
					DbFamily dbFamily = this.CurrentFamily;
					this.lvFamily.LargeImageList.Images.Add(dbFamily.Name, dbFamily.Image);
					this.lvFamily.SmallImageList.Images.Add(dbFamily.Name, dbFamily.Image);
					ListViewItem listViewItem = new ListViewItem();
					listViewItem.Text = dbFamily.Name;
					listViewItem.Tag = dbFamily;
					listViewItem.ImageKey = dbFamily.Name;
					ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
					listViewSubItem.Text = dbFamily.Version;
					listViewItem.SubItems.Add(listViewSubItem);
					ListViewItem.ListViewSubItem listViewSubItem2 = new ListViewItem.ListViewSubItem();
					listViewSubItem2.Text = dbFamily.Date.ToString();
					listViewItem.SubItems.Add(listViewSubItem2);
					ListViewItem.ListViewSubItem listViewSubItem3 = new ListViewItem.ListViewSubItem();
					listViewSubItem3.Text = dbFamily.Database.CategoryTable[dbFamily.ParentId].Name;
					listViewItem.SubItems.Add(listViewSubItem3);
					ListViewItem.ListViewSubItem listViewSubItem4 = new ListViewItem.ListViewSubItem();
					listViewSubItem4.Text = dbFamily.Description.ToString();
					listViewItem.SubItems.Add(listViewSubItem4);
					this.lvFamily.Items.Add(listViewItem);
					listViewItem.Selected = true;
					this.lvFamily.Focus();
					return;
				}
			}
			else
			{
				MessageBox.Show("请在模型文档运行此命令。");
			}
		}

		private void trCategory_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
		{
			TreeNode node = e.Node;
			string text = node.Text;
			Regex regex = new Regex("^[0-9a-zA-Z一-龥]+$");
			if (!text.Equals(e.Label) && e.Label != null && e.Label.Trim() != "" && regex.IsMatch(e.Label) && node.Tag is DbCategory)
			{
				DbCategory dbCategory = (DbCategory)node.Tag;
				try
				{
					if (dbCategory.ReName(e.Label))
					{
						node.Text = e.Label;
					}
					else
					{
						node.Text = text;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
			e.CancelEdit = true;
			this.tvProject.LabelEdit = false;
		}

		private void trFamilyTree_AfterSelect(object sender, TreeViewEventArgs e)
		{
			TreeNode node = e.Node;
			if (node.Tag != null)
			{
				if (node.Tag is DbCategory)
				{
					this.CurrentSubject = (DbSubject)this.FindRoot(node).Tag;
					this.CurrentCategory = (DbCategory)node.Tag;
					this.CurrentFamily = null;
					return;
				}
				if (node.Tag is DbSubject)
				{
					this.CurrentSubject = (DbSubject)this.FindRoot(node).Tag;
					this.CurrentCategory = null;
					this.CurrentFamily = null;
				}
			}
		}

		private void doAddType()
		{
			this.boAdd = true;
			this.boEdit = false;
			this.dgvType.ReadOnly = false;
			this.dgvType.AllowUserToAddRows = true;
			this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.btnOk.Visible = true;
			this.btnCancel.Visible = true;
			this.lvFamily.Enabled = false;
			this.trackBar1.Enabled = false;
			this.tvProject.Enabled = false;
			this.btnAddCategory.Enabled = false;
			this.btnDelCategory.Enabled = false;
			this.btnAddFamily.Enabled = false;
			this.btnDelFamily.Enabled = false;
			this.btnLoadToPro.Enabled = false;
			this.btnEditFamily.Enabled = false;
			this.btnDownload.Enabled = false;
			this.btnAddType.Enabled = false;
			this.btnEditType.Enabled = false;
			this.btnDelType.Enabled = false;
			this.btnTop.Enabled = false;
			this.btnPrevious.Enabled = false;
			this.btnNext.Enabled = false;
			this.btnBottom.Enabled = false;
			this.cbxPageCount.Enabled = false;
			this.btnExit.Enabled = false;
			this.btnDownload.Enabled = false;
			this.tsddbSearch.Enabled = false;
			this.tsddbTools.Enabled = false;
			this.btnPlace.Enabled = false;
			this.rbLocal.Enabled = false;
			this.rbUser.Enabled = false;
			this.rbServer.Enabled = false;
			base.ControlBox = false;
			for (int i = 0; i < this.dgvType.Rows.Count - 1; i++)
			{
                this.dgvType.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Gray;
				this.dgvType.Rows[i].ReadOnly = true;
			}
			this.addRowsNo = this.dgvType.Rows.Count;
			this.dgvType.ContextMenuStrip = this.cmsEditType;
			this.dgvType.Select();
		}

		private void btnAddType_Click(object sender, EventArgs e)
		{
			this.cmdAddType();
		}

		private void cmdAddType()
		{
			if (!this.IsServer)
			{
				this.doAddType();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddFamily())
				{
					this.doAddType();
					return;
				}
				MessageBox.Show("您的账号没有添加规格的权限。");
			}
		}

		private void btnDelFamily_Click(object sender, EventArgs e)
		{
			this.cmdDelFamily();
			this.lvFamily.Focus();
		}

		private void cmdLogin()
		{
			DlgLogin dlgLogin = new DlgLogin();
			if (dlgLogin.ShowDialog(this) == DialogResult.OK && dlgLogin.User != null)
			{
				dlgLogin.User.IncreaseCount();
				this.CurrentUser = dlgLogin.User;
				this.tsslCurrentUser.Text = "";
				this.toolStripStatusLabel2.Text = string.Format("当前登录用户：{0}", this.CurrentUser.Name);
				this.initPermission();
				this.tsLogout.Enabled = true;
			}
		}

		private void cmdDelFamily()
		{
			if (!this.IsServer)
			{
				this.doRemoveFamily();
				this.Recount();
				this.CurrentFamily = null;
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanDelFamily())
				{
					this.doRemoveFamily();
					this.Recount();
					this.CurrentFamily = null;
					return;
				}
				MessageBox.Show("您的账号没有删除族的权限。");
			}
		}

		private void doRemoveFamily()
		{
			if (this.lvFamily.SelectedItems.Count > 0 && this.lvFamily.SelectedItems.Count > 0 && MessageBox.Show("确定要删除选中的族？", "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK)
			{
				this.lvFamily.BeginUpdate();
				foreach (object obj in this.lvFamily.SelectedItems)
				{
					ListViewItem listViewItem = (ListViewItem)obj;
					try
					{
						DbFamily dbFamily = (DbFamily)listViewItem.Tag;
						if (dbFamily.Remove(false))
						{
							listViewItem.Remove();
							this.btnAddType.Enabled = false;
							this.btnEditType.Enabled = false;
							this.btnDelType.Enabled = false;
							this.btnDelFamily.Enabled = false;
							this.btnEditFamily.Enabled = false;
							this.btnDownload.Enabled = false;
							this.dgvType.DataSource = "";
							this.dgvType.ContextMenuStrip = null;
						}
						else
						{
							MessageBox.Show(dbFamily.Name + "删除失败!", "族库管理");
						}
					}
					catch (Exception ex)
					{
						MessageBox.Show(ex.Message);
					}
				}
				this.lvFamily.EndUpdate();
			}
		}

		private void tsmiDelFamily_Click(object sender, EventArgs e)
		{
			this.cmdDelFamily();
		}

		private void doEditType()
		{
			this.boAdd = false;
			this.boEdit = true;
			this.dgvType.ReadOnly = false;
			this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.btnOk.Visible = true;
			this.btnCancel.Visible = true;
			this.lvFamily.Enabled = false;
			this.trackBar1.Enabled = false;
			this.tvProject.Enabled = false;
			this.btnAddCategory.Enabled = false;
			this.btnDelCategory.Enabled = false;
			this.btnAddFamily.Enabled = false;
			this.btnDelFamily.Enabled = false;
			this.btnLoadToPro.Enabled = false;
			this.btnEditFamily.Enabled = false;
			this.btnDownload.Enabled = false;
			this.btnAddType.Enabled = false;
			this.btnEditType.Enabled = false;
			this.btnDelType.Enabled = false;
			this.btnTop.Enabled = false;
			this.btnPrevious.Enabled = false;
			this.btnNext.Enabled = false;
			this.btnBottom.Enabled = false;
			this.cbxPageCount.Enabled = false;
			this.btnExit.Enabled = false;
			this.btnDownload.Enabled = false;
			this.tsddbSearch.Enabled = false;
			this.tsddbTools.Enabled = false;
			this.btnPlace.Enabled = false;
			this.rbLocal.Enabled = false;
			this.rbUser.Enabled = false;
			this.rbServer.Enabled = false;
			base.ControlBox = false;
			foreach (object obj in this.groupBox1.Controls)
			{
                System.Windows.Forms.Control control = (System.Windows.Forms.Control)obj;
				if (control is Button)
				{
					control.Enabled = false;
				}
			}
			foreach (object obj2 in this.groupBox2.Controls)
			{
                System.Windows.Forms.Control control2 = (System.Windows.Forms.Control)obj2;
				if (control2 is Button)
				{
					control2.Enabled = false;
				}
			}
			foreach (object obj3 in this.groupBox3.Controls)
			{
                System.Windows.Forms.Control control3 = (System.Windows.Forms.Control)obj3;
				if (control3 is Button)
				{
					control3.Enabled = false;
				}
			}
			this.dgvType.ContextMenuStrip = this.cmsEditType;
		}

		private void btnEditType_Click(object sender, EventArgs e)
		{
			this.cmdEditType();
		}

		private void cmdEditType()
		{
			if (!this.IsServer)
			{
				this.doEditType();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddFamily())
				{
					this.doEditType();
					return;
				}
				MessageBox.Show("您的账号没有删除规格的权限。");
			}
		}

		private void tsmiAddType_Click(object sender, EventArgs e)
		{
			this.doAddType();
		}

		private void tsmiEditType_Click(object sender, EventArgs e)
		{
			this.doEditType();
		}

		private void tsmiDelType_Click(object sender, EventArgs e)
		{
			this.doDelType();
		}

		private void doDelType()
		{
			if (this.dgvType.SelectedRows.Count > 0 && MessageBox.Show("确定要删除选定的规格？", "族库管理", MessageBoxButtons.OKCancel) == DialogResult.OK)
			{
				FamilyLibDatabase database = this.CurrentSubject.Database;
				DbFamily family = this.CurrentFamily;
				ITypeTable typeTable = database.TypeTable;
				this.dgvType.Columns["TypeId"].Visible = true;
				foreach (object obj in this.dgvType.SelectedRows)
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					try
					{
						typeTable.Remove(Convert.ToInt32(dataGridViewRow.Cells["TypeId"].Value), family);
						this.dgvType.Rows.Remove(dataGridViewRow);
					}
					catch
					{
					}
				}
				this.dgvType.Columns["TypeId"].Visible = false;
			}
		}

		private void btnDelType_Click(object sender, EventArgs e)
		{
			this.cmdDelType();
		}

		private void cmdDelType()
		{
			if (!this.IsServer)
			{
				this.doDelType();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddFamily())
				{
					this.doDelType();
					return;
				}
				MessageBox.Show("您的账号没有删除规格的权限。");
			}
		}

		private void tsmiEditFamilyParams_Click(object sender, EventArgs e)
		{
		}

		private void tsmiOutput_Click(object sender, EventArgs e)
		{
		}

		private void tsmiInput_Click(object sender, EventArgs e)
		{
			this.cmdImport();
		}

		private void btnSelectType_Click(object sender, EventArgs e)
		{
		}

		private void btnOutput_Click(object sender, EventArgs e)
		{
		}

		private void cmdExport(FamilyLibDatabase db)
		{
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.FileName = this.getDbDefName(db);
			saveFileDialog.FilterIndex = 1;
			saveFileDialog.Filter = "族库(*.db)|*.db";
			if (saveFileDialog.ShowDialog() == DialogResult.OK)
			{
				int num = 0;
				if (db.Export(saveFileDialog.FileName, ref num))
				{
					MessageBox.Show("导出完成" + num + "个文件。", "族库管理");
				}
			}
		}

		private string getDbDefName(FamilyLibDatabase db)
		{
			int num = db.Name.LastIndexOf('\\');
			return db.Name.Substring(num + 1, db.Name.Length - num - 1);
		}

		private void cmdImport()
		{
			if (!this.IsServer)
			{
				this.doImport();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanImport())
				{
					this.doImport();
					return;
				}
				MessageBox.Show("您的账号没有导入族库的权限。");
			}
		}

		private void doImport()
		{
			try
			{
				OpenFileDialog openFileDialog = new OpenFileDialog();
				openFileDialog.FilterIndex = 1;
				openFileDialog.Filter = "族库(*.db)|*.db";
				if (openFileDialog.ShowDialog() == DialogResult.OK)
				{
					FamilyLibDatabase familyLibDatabase = new SqliteDatabase(openFileDialog.FileName);
					Guid guid;
					try
					{
						guid = familyLibDatabase.SubjectTable.AllSubject()[0].Guid;
					}
					catch (Exception)
					{
						MessageBox.Show("请正确选择族库文件。");
						return;
					}
					FamilyLibDatabase familyLibDatabase2 = null;
					foreach (FamilyLibDatabase familyLibDatabase3 in this.dbs)
					{
						if (familyLibDatabase3.SubjectTable.AllSubject()[0].Guid == guid)
						{
							familyLibDatabase2 = familyLibDatabase3;
							break;
						}
					}
					if (familyLibDatabase2 == null)
					{
						MessageBox.Show("请检查导入的族库文件，是否与目标分类一致。");
					}
					else
					{
						try
						{
							string value = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf(".") - 4, 4);
							string value2 = familyLibDatabase2.Name.Substring(familyLibDatabase2.Name.LastIndexOf(".") - 4, 4);
							if (Convert.ToInt32(value) > Convert.ToInt32(value2))
							{
								MessageBox.Show("不能导入高版本族库。");
								return;
							}
						}
						catch (Exception)
						{
						}
						DlgCompare dlgCompare = new DlgCompare(familyLibDatabase2, familyLibDatabase);
						if (dlgCompare.ShowDialog() == DialogResult.OK)
						{
							int num = 0;
							if (dlgCompare.CategoryList.Count > 0)
							{
								if (familyLibDatabase2.Import(familyLibDatabase, dlgCompare.CategoryList, ref num))
								{
									MessageBox.Show("导入完成" + num + "个文件。", "族库管理");
									FamilyLibDatabase.FillTree(this.tvProject, this.dbs, CheckType.All);
									if (this.tvProject.Nodes[0].Nodes.Count <= 0)
									{
										this.btnLoadToPro.Enabled = false;
									}
									else
									{
										this.btnLoadToPro.Enabled = true;
									}
								}
								else
								{
									MessageBox.Show("导入被取消。", "族库管理");
								}
							}
							else
							{
								MessageBox.Show("没有选择需要导入的族。", "族库管理");
							}
						}
					}
				}
			}
			catch (Exception)
			{
				MessageBox.Show("请正确选择项目库文件。");
			}
		}

		private void cmdEditOk()
		{
			FamilyLibDatabase database = this.CurrentSubject.Database;
			DbFamily family = this.CurrentFamily;
			ITypeTable typeTable = database.TypeTable;
			try
			{
				typeTable.Update((DataTable)this.dgvType.DataSource, family);
				this.boEdit = false;
			}
			catch (Exception ex)
			{
				MessageBox.Show("修改发生异常。\n" + ex.Message, "族库管理");
			}
			finally
			{
				this.dgvType.DataSource = "";
				this.dgvType.DataSource = typeTable.DataTable(family);
				this.dgvType.Columns["TypeId"].Visible = false;
				this.dgvType.ReadOnly = true;
				this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
				this.btnExit.Enabled = true;
				base.ControlBox = true;
			}
		}

		private void cmdCancel()
		{
			this.boAdd = false;
			this.boEdit = false;
			this.btnOk.Visible = false;
			this.btnCancel.Visible = false;
			FamilyLibDatabase database = this.CurrentSubject.Database;
			DbCategory dbCategory = this.CurrentCategory;
			DbFamily family = this.CurrentFamily;
			ITypeTable typeTable = database.TypeTable;
			this.dgvType.AllowUserToAddRows = false;
			this.dgvType.DataSource = "";
			this.dgvType.DataSource = typeTable.DataTable(family);
			this.dgvType.Columns["TypeId"].Visible = false;
			this.dgvType.AllowUserToAddRows = false;
			this.dgvType.ReadOnly = true;
			this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvType.ContextMenuStrip = this.cmsType;
		}

		private void cmdAddOk()
		{
			try
			{
				DataTable dataTable = (DataTable)this.dgvType.DataSource;
				DataTable dataTable2 = dataTable.Copy();
				dataTable2.Rows.Clear();
				for (int i = this.addRowsNo - 1; i < dataTable.Rows.Count; i++)
				{
					dataTable2.ImportRow(dataTable.Rows[i]);
				}
				this.CurrentFamily.AddType(dataTable2);
				this.boAdd = false;
			}
			catch
			{
				MessageBox.Show("添加发生异常", "族库管理");
			}
			finally
			{
				this.dgvType.AllowUserToAddRows = false;
				this.dgvType.DataSource = "";
				this.dgvType.DataSource = this.CurrentFamily.Database.TypeTable.DataTable(this.CurrentFamily);
				this.dgvType.Columns["TypeId"].Visible = false;
				this.dgvType.AllowUserToAddRows = false;
				this.dgvType.ReadOnly = true;
				this.dgvType.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
				this.btnExit.Enabled = true;
				base.ControlBox = true;
			}
		}

		private void AddCategoryToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.dgvType.GetCellCount(DataGridViewElementStates.Selected) > 0)
			{
				try
				{
					Clipboard.Clear();
					Clipboard.SetDataObject(this.dgvType.GetClipboardContent());
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message.ToString());
				}
			}
		}

		private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.dgvType.CurrentRow.Index < 0)
			{
				return;
			}
			string text = Clipboard.GetText();
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			string[] array = text.Trim().Split(new char[]
			{
				'\n'
			});
			if (array.Length < 0)
			{
				return;
			}
			string[] array2 = array[0].Split(new char[]
			{
				'\t'
			});
			int num = array2.Length;
			DataTable dataTable = this.dgvType.DataSource as DataTable;
			DataRow dataRow = dataTable.NewRow();
			for (int i = 0; i < num; i++)
			{
				string value = array2[i].Trim();
				dataRow[i + 1] = value;
			}
			dataTable.Rows.Add(dataRow);
			this.dgvType.DataSource = dataTable;
		}

		private void trFamilyTree_MouseDown(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				TreeNode nodeAt = this.tvProject.GetNodeAt(e.X, e.Y);
				if (nodeAt != null)
				{
					this.tvProject.SelectedNode = nodeAt;
				}
			}
		}

		private void ReNameToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.CurrentCategory.Limit)
			{
				MessageBox.Show("系统分类无法重命名", "族库管理");
				return;
			}
			this.tvProject.LabelEdit = true;
			this.tvProject.SelectedNode.BeginEdit();
		}

		private void trackBar1_Scroll(object sender, EventArgs e)
		{
			switch (this.trackBar1.Value)
			{
			case 0:
            this.lvFamily.View = System.Windows.Forms.View.Details;
				this.lvFamily.FullRowSelect = true;
				break;
			case 1:
                this.lvFamily.View = System.Windows.Forms.View.List;
				break;
			case 2:
                this.lvFamily.View = System.Windows.Forms.View.LargeIcon;
				break;
			}
			this.lvFamily.Select();
			this.lvFamily.Focus();
		}

		private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
		{
			ListView listView = sender as ListView;
			if (e.Column != (listView.ListViewItemSorter as DlgFamilyManagerForPro.ListViewColumnSorter).ColumnToSort)
			{
				(listView.ListViewItemSorter as DlgFamilyManagerForPro.ListViewColumnSorter).ColumnToSort = e.Column;
				(listView.ListViewItemSorter as DlgFamilyManagerForPro.ListViewColumnSorter).OrderOfSort = SortOrder.Ascending;
				return;
			}
			if ((listView.ListViewItemSorter as DlgFamilyManagerForPro.ListViewColumnSorter).OrderOfSort == SortOrder.Ascending)
			{
				(listView.ListViewItemSorter as DlgFamilyManagerForPro.ListViewColumnSorter).OrderOfSort = SortOrder.Descending;
				return;
			}
			(listView.ListViewItemSorter as DlgFamilyManagerForPro.ListViewColumnSorter).OrderOfSort = SortOrder.Ascending;
		}

		private void listView1_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.lvFamily.SelectedItems.Count == 1)
			{
				this.CurrentFamily = (DbFamily)this.lvFamily.SelectedItems[0].Tag;
			}
		}

		public void ShowType()
		{
			this.dgvType.DataSource = null;
			DataTable dataTable = this.CurrentFamily.Database.TypeTable.DataTable(this.CurrentFamily);
			if (dataTable != null)
			{
				this.dgvType.DataSource = dataTable;
				this.dgvType.Columns["TypeId"].Visible = false;
				this.dgvType.AutoResizeColumns();
				this.dgvType.AllowUserToResizeColumns = true;
			}
		}

		private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
		{
			string text = this.lvFamily.Items[e.Item].Text;
			if (this.lvFamily.Items[e.Item].Tag is DbFamily && e.Label != null && e.Label != "" && !text.Equals(e.Label))
			{
				if (((DbFamily)this.lvFamily.Items[e.Item].Tag).Rename(e.Label))
				{
					this.lvFamily.Items[e.Item].Text = e.Label;
				}
				else
				{
					this.lvFamily.Items[e.Item].Text = text;
				}
			}
			e.CancelEdit = true;
			this.lvFamily.LabelEdit = false;
		}

		private void tsmAbout(object sender, EventArgs e)
		{
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			DataTable dataTable = (DataTable)this.dgvType.DataSource;
			char[] array = new char[]
			{
				'\\',
				':',
				'{',
				'}',
				'[',
				']',
				'|',
				';',
				'<',
				'>',
				'?',
				'\'',
				'~',
				'`'
			};
			if (this.boAdd)
			{
				for (int i = this.addRowsNo - 1; i < dataTable.Rows.Count; i++)
				{
					string source = dataTable.Rows[i][1].ToString();
					foreach (char value in array)
					{
						if (source.Contains(value))
						{
							MessageBox.Show("规格名称不能包含以下字符： " + value.ToString());
							foreach (object obj in this.dgvType.SelectedRows)
							{
								((DataGridViewRow)obj).Selected = false;
							}
							this.dgvType.Rows[i].Cells[1].Selected = true;
							return;
						}
					}
				}
			}
			else if (this.boEdit)
			{
				for (int k = 0; k < dataTable.Rows.Count; k++)
				{
					string source2 = dataTable.Rows[k][1].ToString();
					foreach (char value2 in array)
					{
						if (source2.Contains(value2))
						{
							MessageBox.Show("规格名称不能包含以下字符： " + value2.ToString());
							foreach (object obj2 in this.dgvType.SelectedRows)
							{
								((DataGridViewRow)obj2).Selected = false;
							}
							this.dgvType.Rows[k].Cells[1].Selected = true;
							return;
						}
					}
				}
			}
			try
			{
				if (this.boAdd)
				{
					this.cmdAddOk();
				}
				else if (this.boEdit)
				{
					this.cmdEditOk();
				}
			}
			catch
			{
			}
			this.btnOk.Visible = false;
			this.btnCancel.Visible = false;
			this.lvFamily.Enabled = true;
			this.trackBar1.Enabled = true;
			this.tvProject.Enabled = true;
			this.btnLoadToPro.Enabled = true;
			this.btnAddCategory.Enabled = true;
			this.btnDelCategory.Enabled = true;
			this.btnAddFamily.Enabled = true;
			this.btnDelFamily.Enabled = true;
			this.btnLoadToPro.Enabled = true;
			this.btnEditFamily.Enabled = true;
			this.btnDownload.Enabled = true;
			this.btnAddType.Enabled = true;
			this.btnEditType.Enabled = true;
			this.btnDelType.Enabled = true;
			this.btnDownload.Enabled = true;
			this.tsddbSearch.Enabled = true;
			this.tsddbTools.Enabled = true;
			this.btnPlace.Enabled = true;
			this.rbLocal.Enabled = true;
			this.rbUser.Enabled = true;
			this.rbServer.Enabled = true;
			if (this.cbxPageCount.SelectedIndex == 0)
			{
				this.btnTop.Enabled = false;
				this.btnPrevious.Enabled = false;
			}
			else
			{
				this.btnTop.Enabled = true;
				this.btnPrevious.Enabled = true;
			}
			if (this.cbxPageCount.SelectedIndex == this.cbxPageCount.Items.Count - 1)
			{
				this.btnNext.Enabled = false;
				this.btnBottom.Enabled = false;
			}
			else
			{
				this.btnNext.Enabled = true;
				this.btnBottom.Enabled = true;
			}
			this.cbxPageCount.Enabled = true;
			this.dgvType.ContextMenuStrip = this.cmsType;
			if (this.dgvType.SelectedRows.Count > 0)
			{
				this.btnDelType.Enabled = true;
				this.btnEditType.Enabled = true;
				return;
			}
			this.btnDelType.Enabled = false;
			this.btnEditType.Enabled = false;
		}

		private void inputToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdImport();
		}

		private void outputToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdExport();
		}

		private void exitToolStripMenuItem_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void helpToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void groupBox3_Enter(object sender, EventArgs e)
		{
		}

		private void btnAddOk_Click(object sender, EventArgs e)
		{
		}

		private void btnAddCancel_Click(object sender, EventArgs e)
		{
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.cmdCancel();
			this.lvFamily.Enabled = true;
			this.trackBar1.Enabled = true;
			this.tvProject.Enabled = true;
			this.btnAddCategory.Enabled = true;
			this.btnDelCategory.Enabled = true;
			this.btnAddFamily.Enabled = true;
			this.btnDelFamily.Enabled = true;
			this.btnLoadToPro.Enabled = true;
			this.btnEditFamily.Enabled = true;
			this.btnDownload.Enabled = true;
			this.btnAddType.Enabled = true;
			this.btnEditType.Enabled = true;
			this.btnDelType.Enabled = true;
			this.btnExit.Enabled = true;
			this.btnDownload.Enabled = true;
			this.tsddbSearch.Enabled = true;
			this.tsddbTools.Enabled = true;
			this.btnPlace.Enabled = true;
			this.rbLocal.Enabled = true;
			this.rbUser.Enabled = true;
			this.rbServer.Enabled = true;
			base.ControlBox = true;
			if (this.cbxPageCount.SelectedIndex == 0)
			{
				this.btnTop.Enabled = false;
				this.btnPrevious.Enabled = false;
			}
			else
			{
				this.btnTop.Enabled = true;
				this.btnPrevious.Enabled = true;
			}
			if (this.cbxPageCount.SelectedIndex == this.cbxPageCount.Items.Count - 1)
			{
				this.btnNext.Enabled = false;
				this.btnBottom.Enabled = false;
			}
			else
			{
				this.btnNext.Enabled = true;
				this.btnBottom.Enabled = true;
			}
			this.cbxPageCount.Enabled = true;
			if (this.dgvType.SelectedRows.Count > 0)
			{
				this.btnDelType.Enabled = true;
				this.btnEditType.Enabled = true;
				return;
			}
			this.btnDelType.Enabled = false;
			this.btnEditType.Enabled = false;
		}

		private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
		{
		}

		private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void AddTypeToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			this.cmdAddType();
		}

		private void RemoveTypeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdDelType();
		}

		private void EditTypeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdEditType();
		}

		private void addCategoryToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			this.cmdAddCategory();
		}

		private void removeToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.tvProject.SelectedNode == null)
			{
				MessageBox.Show("请选择需删除的分类节点");
				return;
			}
			this.cmdDelCategory();
		}

		private void AddFamilyToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdAddFamily();
		}

		private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdDelFamily();
		}

		private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdEditFamily();
		}

		private void addFamilyToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			this.cmdAddFamily();
		}

		private void 添加分类ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdAddProject();
		}

		private void 重命名ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.lvFamily.SelectedItems.Count > 0)
			{
				if (this.CurrentFamily.Limit)
				{
					MessageBox.Show("系统族无法重命名", "族库管理");
					return;
				}
				this.lvFamily.LabelEdit = true;
				this.lvFamily.SelectedItems[0].BeginEdit();
			}
		}

		private void btnEditCategoryParam_Click(object sender, EventArgs e)
		{
			try
			{
				this.loadAllSelectedCategory(this.tvProject.Nodes);
				MessageBox.Show("加载成功", "族库管理");
			}
			catch (Exception)
			{
				MessageBox.Show("加载失败", "族库管理");
			}
		}

		private void loadAllSelectedCategory(TreeNodeCollection tnc)
		{
			foreach (object obj in tnc)
			{
				TreeNode treeNode = (TreeNode)obj;
				if (treeNode.Checked)
				{
					DbCategory dbCategory = treeNode.Tag as DbCategory;
					if (dbCategory != null)
					{
						foreach (DbFamily dbFamily in dbCategory.GetAllFamilies(false, CheckType.All))
						{
							dbFamily.Load(this.m_uiApp.ActiveUIDocument.Document);
						}
					}
				}
				this.loadAllSelectedCategory(treeNode.Nodes);
			}
		}

		private void cmdEditCategory()
		{
			if (!this.IsServer)
			{
				this.doEditCategory();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanAddFamily())
				{
					this.doEditCategory();
					return;
				}
				MessageBox.Show("您的账号没有编辑分类的权限。");
			}
		}

		private void doEditCategory()
		{
		}

		private void editCategoryToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			this.cmdEditCategory();
		}

		private void 导出ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdExport();
		}

		private void cmdExport()
		{
			if (!this.IsServer)
			{
				this.doExport();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanExport())
				{
					this.doExport();
					return;
				}
				MessageBox.Show("您的账号没有导出族库的权限。");
			}
		}

		private void doExport()
		{
			if (this.tvProject.SelectedNode == null)
			{
				MessageBox.Show("请选中要导出的项目", "族库管理");
				return;
			}
			this.cmdExport(this.CurrentSubject.Database);
		}

		private void 导入ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdImport();
		}

		private void dgvType_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{
		}

		private void 登陆服务器ToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void 服务器ToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void 本地族库ToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void dgvType_SortCompare_1(object sender, DataGridViewSortCompareEventArgs e)
		{
			double num;
			double.TryParse(e.CellValue1.ToString().Trim(), out num);
			double num2;
			double.TryParse(e.CellValue2.ToString().Trim(), out num2);
			if (num < num2)
			{
				e.SortResult = -1;
			}
			else if (num == num2)
			{
				e.SortResult = 0;
			}
			else
			{
				e.SortResult = 1;
			}
			e.Handled = true;
		}

		private void dgvType_Sorted(object sender, EventArgs e)
		{
		}

		private void button1_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void cbxPageCount_SelectedIndexChanged(object sender, EventArgs e)
		{
			try
			{
				this.btnTop.Enabled = true;
				this.btnPrevious.Enabled = true;
				this.btnNext.Enabled = true;
				this.btnBottom.Enabled = true;
				if (this.cbxPageCount.SelectedIndex == 0)
				{
					this.btnTop.Enabled = false;
					this.btnPrevious.Enabled = false;
				}
				else
				{
					this.btnTop.Enabled = true;
					this.btnPrevious.Enabled = true;
				}
				if (this.cbxPageCount.SelectedIndex == this.cbxPageCount.Items.Count - 1)
				{
					this.btnNext.Enabled = false;
					this.btnBottom.Enabled = false;
				}
				else
				{
					this.btnNext.Enabled = true;
					this.btnBottom.Enabled = true;
				}
				this.lvFamily.Items.Clear();
				this.lvFamily.LargeImageList.Images.Clear();
				this.lvFamily.SmallImageList.Images.Clear();
				int num = Convert.ToInt32(this.cbxPageCount.SelectedItem);
				List<DbFamily> list = new List<DbFamily>();
				if (this.searchMode == SearchMode.Category)
				{
					if (this.CurrentCategory == null)
					{
						return;
					}
					list = this.searchDb.FamilyTable[this.CurrentCategory, (num - 1) * DlgFamilyManagerForPro.pageContainment, num * DlgFamilyManagerForPro.pageContainment, CheckType.All];
				}
				else if (this.searchMode == SearchMode.Name)
				{
					list = this.searchDb.FamilyTable.SearchFamily(this.searchName, (num - 1) * DlgFamilyManagerForPro.pageContainment, num * DlgFamilyManagerForPro.pageContainment);
				}
				else if (this.searchMode == SearchMode.Time)
				{
					list = this.searchDb.FamilyTable.SearchFamily(this.searchStartTime, this.searchEndTime, (num - 1) * DlgFamilyManagerForPro.pageContainment, num * DlgFamilyManagerForPro.pageContainment);
				}
				this.lvFamily.BeginUpdate();
				foreach (DbFamily dbFamily in list)
				{
					this.lvFamily.LargeImageList.Images.Add(dbFamily.Name, dbFamily.Image);
					this.lvFamily.SmallImageList.Images.Add(dbFamily.Name, dbFamily.Image);
					ListViewItem listViewItem = new ListViewItem();
					listViewItem.Text = dbFamily.Name;
					listViewItem.Tag = dbFamily;
					listViewItem.ImageKey = dbFamily.Name;
					ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
					listViewSubItem.Text = dbFamily.Version;
					listViewItem.SubItems.Add(listViewSubItem);
					ListViewItem.ListViewSubItem listViewSubItem2 = new ListViewItem.ListViewSubItem();
					listViewSubItem2.Text = dbFamily.Date.ToString();
					listViewItem.SubItems.Add(listViewSubItem2);
					ListViewItem.ListViewSubItem listViewSubItem3 = new ListViewItem.ListViewSubItem();
					listViewSubItem3.Text = this.searchDb.CategoryTable[dbFamily.ParentId].Name;
					listViewItem.SubItems.Add(listViewSubItem3);
					ListViewItem.ListViewSubItem listViewSubItem4 = new ListViewItem.ListViewSubItem();
					listViewSubItem4.Text = dbFamily.Description;
					listViewItem.SubItems.Add(listViewSubItem4);
					this.lvFamily.Items.Add(listViewItem);
				}
				this.lvFamily.EndUpdate();
				this.lvFamily.Focus();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void button3_Click(object sender, EventArgs e)
		{
			if (this.cbxPageCount.SelectedIndex != -1)
			{
				if (this.cbxPageCount.SelectedIndex != 0)
				{
                    System.Windows.Forms.ComboBox comboBox = this.cbxPageCount;
					int selectedIndex = comboBox.SelectedIndex;
					comboBox.SelectedIndex = selectedIndex - 1;
				}
				this.lvFamily.Focus();
			}
		}

		private void button4_Click(object sender, EventArgs e)
		{
			if (this.cbxPageCount.SelectedIndex < this.cbxPageCount.Items.Count - 1)
			{
                System.Windows.Forms.ComboBox comboBox = this.cbxPageCount;
				int selectedIndex = comboBox.SelectedIndex;
				comboBox.SelectedIndex = selectedIndex + 1;
			}
			this.lvFamily.Focus();
		}

		private void button2_Click(object sender, EventArgs e)
		{
			if (this.cbxPageCount.SelectedIndex != -1)
			{
				this.cbxPageCount.SelectedIndex = 0;
				this.lvFamily.Focus();
			}
		}

		private void button5_Click(object sender, EventArgs e)
		{
			this.cbxPageCount.SelectedIndex = this.cbxPageCount.Items.Count - 1;
			this.lvFamily.Focus();
		}

		private void dgvType_DataError(object sender, DataGridViewDataErrorEventArgs e)
		{
			MessageBox.Show("输入的格式不正确，请检查后重新输入。");
		}

		private void dgvType_SelectionChanged(object sender, EventArgs e)
		{
			if (this.boAdd || this.boEdit)
			{
				return;
			}
			if (this.dgvType.SelectedRows.Count > 0)
			{
				this.btnDelType.Enabled = true;
				this.btnEditType.Enabled = true;
				this.btnPlace.Visible = true;
				return;
			}
			this.btnDelType.Enabled = false;
			this.btnEditType.Enabled = false;
			this.btnPlace.Visible = false;
		}

		private void 加载ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			Document document = this.m_uiApp.ActiveUIDocument.Document;
			UIDocument activeUIDocument = this.m_uiApp.ActiveUIDocument;
			Family family = this.CurrentFamily.Load(document);
			try
			{
				if (family.Document == document)
				{
					MessageBox.Show("加载完成。");
				}
				else
				{
					MessageBox.Show("加载失败。");
				}
			}
			catch
			{
				MessageBox.Show("加载失败。");
			}
		}

		private void toolStripButton1_Click(object sender, EventArgs e)
		{
		}

		private void cmdSearch(string name, FamilyLibDatabase db)
		{
			if (db != null)
			{
				this.searchMode = SearchMode.Name;
				this.btnTop.Enabled = false;
				this.btnBottom.Enabled = false;
				this.btnNext.Enabled = false;
				this.btnPrevious.Enabled = false;
				this.cbxPageCount.Items.Clear();
				this.dgvType.DataSource = "";
				this.familyCount = db.FamilyTable.SearchFamilyCount(name);
				if (this.familyCount == 0)
				{
					MessageBox.Show("没有找到符合搜索条件的族。");
					return;
				}
				if (this.familyCount < DlgFamilyManagerForPro.pageContainment)
				{
					this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment + 1;
				}
				else if (this.familyCount % DlgFamilyManagerForPro.pageContainment > 0)
				{
					this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment + 1;
				}
				else
				{
					this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment;
				}
				this.label2.Text = "/" + this.pageCount.ToString();
				this.cbxPageCount.Items.Clear();
				for (int i = 1; i <= this.pageCount; i++)
				{
					this.cbxPageCount.Items.Add(i);
				}
				if (this.cbxPageCount.Items.Count > 0)
				{
					this.cbxPageCount.SelectedIndex = 0;
					this.CurrentFamily = (this.cbxPageCount.SelectedItem as DbFamily);
				}
			}
		}

		private void cmdSearch(DateTime startTime, DateTime endTime, FamilyLibDatabase db)
		{
			if (db != null)
			{
				this.searchMode = SearchMode.Time;
				this.btnTop.Enabled = false;
				this.btnBottom.Enabled = false;
				this.btnNext.Enabled = false;
				this.btnPrevious.Enabled = false;
				this.cbxPageCount.Items.Clear();
				this.dgvType.DataSource = "";
				this.familyCount = db.FamilyTable.SearchFamilyCount(startTime, endTime);
				if (this.familyCount == 0)
				{
					MessageBox.Show("没有找到符合搜索条件的族。");
					return;
				}
				if (this.familyCount < DlgFamilyManagerForPro.pageContainment)
				{
					this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment + 1;
				}
				else if (this.familyCount % DlgFamilyManagerForPro.pageContainment > 0)
				{
					this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment + 1;
				}
				else
				{
					this.pageCount = this.familyCount / DlgFamilyManagerForPro.pageContainment;
				}
				this.label2.Text = "/" + this.pageCount.ToString();
				this.cbxPageCount.Items.Clear();
				for (int i = 1; i <= this.pageCount; i++)
				{
					this.cbxPageCount.Items.Add(i);
				}
				if (this.cbxPageCount.Items.Count > 0)
				{
					this.cbxPageCount.SelectedIndex = 0;
				}
			}
		}

		private void tstbSearchName_Enter(object sender, EventArgs e)
		{
		}

		private void tstbSearchName_Click(object sender, EventArgs e)
		{
		}

		private void tstbSearchName_KeyDown(object sender, KeyEventArgs e)
		{
		}

		private void tsmiUserPath_Click(object sender, EventArgs e)
		{
			UserDbData userDbData = ConfigUtils.ReadFamilyLibXmlFile("User", this.m_uiApp.Application.VersionNumber) as UserDbData;
			using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
			{
				if (userDbData != null)
				{
					folderBrowserDialog.SelectedPath = userDbData.DatabasePath;
				}
				if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
				{
					this.userPath = folderBrowserDialog.SelectedPath;
				}
			}
			if (FamilyLibDatabase.GetUserDbs(this.userPath, this.m_uiApp.Application.VersionNumber).Count < 5)
			{
				Assist.FileUtil.WriteFile(Resource1.ResourceManager.GetObject("Architecture") as byte[], this.userPath + "\\Architecture" + this.m_uiApp.Application.VersionNumber + ".db");
				Assist.FileUtil.WriteFile(Resource1.ResourceManager.GetObject("Electric") as byte[], this.userPath + "\\Electric" + this.m_uiApp.Application.VersionNumber + ".db");
				Assist.FileUtil.WriteFile(Resource1.ResourceManager.GetObject("Plumbing") as byte[], this.userPath + "\\Plumbing" + this.m_uiApp.Application.VersionNumber + ".db");
				Assist.FileUtil.WriteFile(Resource1.ResourceManager.GetObject("HVAC") as byte[], this.userPath + "\\HVAC" + this.m_uiApp.Application.VersionNumber + ".db");
				Assist.FileUtil.WriteFile(Resource1.ResourceManager.GetObject("System") as byte[], this.userPath + "\\System" + this.m_uiApp.Application.VersionNumber + ".db");
			}
			UserDbData data = new UserDbData(this.userPath);
			ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), "项目族库类型", this.m_uiApp.Application.VersionNumber, data);
		}

		private void tsmiServer_Click(object sender, EventArgs e)
		{
		}

		private void rbLocal_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbLocal.Checked)
			{
				try
				{
					this.dbs.Clear();
					this.proDb = FamilyLibDatabase.GetSqliteDB(string.Format("Project{0}.db", this.m_uiApp.Application.VersionNumber), this.m_uiApp.Application.VersionNumber);
					this.dbs.Add(this.proDb);
					FamilyLibDatabase.FillTree(this.tvProject, this.dbs, CheckType.All);
					if (this.tvProject.Nodes[0].Nodes.Count <= 0)
					{
						this.btnLoadToPro.Enabled = false;
					}
					else
					{
						this.btnLoadToPro.Enabled = true;
					}
					this.lvFamily.Items.Clear();
					this.dgvType.DataSource = null;
					this.IsServer = false;
					this.btnDownload.Visible = false;
					this.tsddbLogin.Enabled = false;
					this.tsddbCommunication.Enabled = false;
					this.toolStripStatusLabel2.Visible = false;
					this.rbTemp = this.rbLocal;
					this.currentCategory = null;
					this.currentSubject = null;
					this.currentFamily = null;
					this.timer1.Enabled = false;
					LocalProjectDbData data = new LocalProjectDbData("");
					ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), this.m_uiApp.Application.VersionNumber, "项目族库类型", data);
					return;
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
					if (this.rbTemp != null)
					{
						this.rbTemp.Checked = true;
					}
					return;
				}
			}
			this.rbTemp = this.rbLocal;
		}

		private void rbUser_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbUser.Checked)
			{
				try
				{
					this.tsddbLogin.Enabled = false;
					UserDbData userDbData = ConfigUtils.ReadFamilyLibXmlFile("User", this.m_uiApp.Application.VersionNumber) as UserDbData;
					if (userDbData.DatabasePath == "")
					{
						MessageBox.Show("请先打开‘设置’功能设置用户族库路径。");
						this.rbTemp.Checked = true;
					}
					else
					{
						ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), this.m_uiApp.Application.VersionNumber, "项目族库类型", userDbData);
						this.dbs = FamilyLibDatabase.GetDbs(this.m_uiApp.Application.VersionNumber);
						FamilyLibDatabase.FillTree(this.tvProject, this.dbs, CheckType.All);
						if (this.tvProject.Nodes[0].Nodes.Count <= 0)
						{
							this.btnLoadToPro.Enabled = false;
						}
						else
						{
							this.btnLoadToPro.Enabled = true;
						}
						this.lvFamily.Items.Clear();
						this.dgvType.DataSource = null;
						this.IsServer = false;
						this.btnDownload.Visible = false;
						this.tsddbLogin.Enabled = false;
						this.tsddbCommunication.Enabled = false;
						this.toolStripStatusLabel2.Visible = true;
						this.rbTemp = this.rbUser;
						this.CurrentCategory = null;
						this.CurrentSubject = null;
						this.CurrentFamily = null;
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
					if (this.rbTemp != null)
					{
						this.rbTemp.Checked = true;
					}
				}
			}
		}

		private void rbServer_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbServer.Checked)
			{
				try
				{
					if (XmlUtils.GetDataFromConfigFile(AssistFunc.GetAppRootPath() + "\\Data\\Config.xml", "Server", "value") == "")
					{
						MessageBox.Show("请先运行‘服务器连接配置’命令配置服务器。");
						this.rbTemp.Checked = true;
					}
					else
					{
						this.dbs.Clear();
						ServerDbData data = new ServerDbData("", "", "");
						ConfigUtils.WriteFamilyLibXmlFile(ConfigUtils.GetDbConfigFileName(), this.m_uiApp.Application.VersionNumber, "项目族库类型", data);
						this.proDb = FamilyLibDatabase.GetMySqlProjectDb(ConfigUtils.GetDbConfigFileName(), string.Format("Project{0}", this.m_uiApp.Application.VersionNumber));
						if (this.proDb == null)
						{
							MessageBox.Show("请先运行‘服务器连接配置’命令配置服务器。");
						}
						else
						{
							this.dbs.Add(this.proDb);
							this.lvFamily.Items.Clear();
							FamilyLibDatabase.FillTree(this.tvProject, this.dbs, CheckType.All);
							if (this.tvProject.Nodes[0].Nodes.Count <= 0)
							{
								this.btnLoadToPro.Enabled = false;
							}
							else
							{
								this.btnLoadToPro.Enabled = true;
							}
							this.toolStripStatusLabel2.Visible = true;
							this.dgvType.DataSource = null;
							this.btnDownload.Visible = true;
							this.IsServer = true;
							this.tsddbLogin.Enabled = true;
							this.autoLogin();
							this.rbTemp = this.rbServer;
							this.currentCategory = null;
							this.currentSubject = null;
							this.currentFamily = null;
							this.timer1.Enabled = true;
						}
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.Message);
					if (this.rbTemp != null)
					{
						this.rbTemp.Checked = true;
					}
				}
			}
		}

		private void autoLogin()
		{
			if (!DlgLogin.IsAutoLogin())
			{
				return;
			}
			string fileName = AssistFunc.GetAppRootPath() + "\\Data\\Config.xml";
			DbUser user = DbUser.GetUser(XmlUtils.GetDataFromConfigFile(fileName, "AutoUser", "value"), BimServerDB.Default);
			if (user == null)
			{
				return;
			}
			string dataFromConfigFile = XmlUtils.GetDataFromConfigFile(fileName, "AutoPwd", "value");
			if (!user.Password.Equals(DbUser.ToMd5(dataFromConfigFile)))
			{
				return;
			}
			this.CurrentUser = user;
			user.IncreaseCount();
			this.tsslCurrentUser.Text = "";
			this.toolStripStatusLabel2.Text = string.Format("当前登录用户：{0}", this.CurrentUser.Name);
			if (!this.rbLocal.Checked)
			{
				this.initPermission();
			}
			this.tsLogout.Enabled = true;
		}

		private void CreateCategoryByFolder(DbCategory category, DirectoryInfo rootDir)
		{
			foreach (FileInfo fileInfo in rootDir.GetFiles())
			{
				if (fileInfo.Extension == ".rfa")
				{
					try
					{
						string fullName = fileInfo.FullName;
						PictureBox pictureBox = new PictureBox();
						ListBox listBox = new ListBox();
						ListBox listBox2 = new ListBox();
						int length = fileInfo.Name.LastIndexOf(".");
						string name = fileInfo.Name.Substring(0, length);
						FamilyLibDatabase database = this.CurrentSubject.Database;
						FamilyUtil.GetFamilyPreview(this.m_uiApp, fullName, pictureBox);
						FamilyUtil.GetFamilyTypeParams(this.m_uiApp, fullName, listBox2, category);
						FamilyUtil.GetFamilyInstanceParams(this.m_uiApp, fullName, listBox, listBox2);
						foreach (DbParamDefinition dbParamDefinition in category.GetParamDefinitionList())
						{
							bool flag = false;
							IEnumerator enumerator2 = listBox2.Items.GetEnumerator();
							{
								while (enumerator2.MoveNext())
								{
									if (((DbParamDefinition)enumerator2.Current).Name == dbParamDefinition.Name)
									{
										flag = true;
										break;
									}
								}
							}
							if (!flag)
							{
								MessageBox.Show("族中不存在分类关键参数：" + dbParamDefinition.Name + "。\n请添加后再入库", "族库管理");
								return;
							}
						}
						DbFamily dbFamily = new DbFamily(fullName, pictureBox.Image);
						dbFamily.Version = this.m_uiApp.Application.VersionNumber;
						dbFamily.SetDate(DateTime.Now);
						foreach (object obj in listBox.Items)
						{
							DbParamDefinition item = (DbParamDefinition)obj;
							dbFamily.ParamDefinitionList.Add(item);
						}
						foreach (object obj2 in listBox2.Items)
						{
							DbParamDefinition item2 = (DbParamDefinition)obj2;
							dbFamily.ParamDefinitionList.Add(item2);
						}
						dbFamily.Description = "";
						dbFamily.Name = name;
						if (category.AddFamily(dbFamily, fileInfo))
						{
							dbFamily.RecordTypes(this.m_uiApp.ActiveUIDocument.Document, category.Database, fileInfo.FullName);
							this.lvFamily.LargeImageList.Images.Add(dbFamily.Name, dbFamily.Image);
							this.lvFamily.SmallImageList.Images.Add(dbFamily.Name, dbFamily.Image);
							ListViewItem listViewItem = new ListViewItem();
							listViewItem.Text = dbFamily.Name;
							listViewItem.Tag = dbFamily;
							listViewItem.ImageKey = dbFamily.Name;
							ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
							listViewSubItem.Text = dbFamily.Version;
							listViewItem.SubItems.Add(listViewSubItem);
							ListViewItem.ListViewSubItem listViewSubItem2 = new ListViewItem.ListViewSubItem();
							listViewSubItem2.Text = dbFamily.Date.ToString();
							listViewItem.SubItems.Add(listViewSubItem2);
							ListViewItem.ListViewSubItem listViewSubItem3 = new ListViewItem.ListViewSubItem();
							listViewSubItem3.Text = category.Name;
							listViewItem.SubItems.Add(listViewSubItem3);
							ListViewItem.ListViewSubItem listViewSubItem4 = new ListViewItem.ListViewSubItem();
							listViewSubItem4.Text = dbFamily.Description;
							listViewItem.SubItems.Add(listViewSubItem4);
							this.lvFamily.Items.Add(listViewItem);
						}
					}
					catch (Exception ex)
					{
						MessageBox.Show(ex.Message);
					}
				}
			}
			foreach (DirectoryInfo directoryInfo in rootDir.GetDirectories())
			{
				DbCategory category2 = new DbCategory(directoryInfo.Name);
				category.AddCategory(category2);
				this.CreateCategoryByFolder(category2, directoryInfo);
			}
		}

		private string getParamValue(Document doc, Parameter param)
		{
			string result = "";
            switch ((int)param.StorageType)
			{
			case 1:
				result = 0.ToString();
				try
				{
					result = param.AsInteger().ToString();
                    if ((int)param.DisplayUnitType != -2)
					{
						result = ((double)param.AsInteger() * Convert.ToDouble(UnitConvertC.ImperialDutRatio(param.DisplayUnitType))).ToString();
					}
					return result;
				}
				catch (Exception)
				{
					return result;
				}
				goto IL_F2;
			case 2:
				result = 0.0.ToString();
				try
				{
                    if ((int)param.DisplayUnitType != -2)
					{
						result = Math.Round(param.AsDouble() * Convert.ToDouble(UnitConvertC.ImperialDutRatio(param.DisplayUnitType)), 1).ToString();
					}
					else
					{
						result = Math.Round(param.AsDouble(), 1).ToString();
					}
					return result;
				}
				catch (Exception)
				{
					return result;
				}
				break;
			case 3:
				goto IL_F2;
			case 4:
				break;
			default:
				return result;
			}
			ElementId id = param.AsElementId();
			Element element = RevitVersionFuncs.GetElement(doc, id);
			if (element != null)
			{
				return element.Name;
			}
			return result;
			IL_F2:
			try
			{
				result = param.AsString();
			}
			catch (Exception)
			{
			}
			return result;
		}

		private void 导入族文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!this.IsServer)
			{
				this.cmdImportFolder();
				return;
			}
			if (this.CurrentUser == null)
			{
				DlgLogin dlgLogin = new DlgLogin();
				if (dlgLogin.ShowDialog(this) == DialogResult.OK && dlgLogin.User != null)
				{
					if (dlgLogin.User.Status == UserStatus.Unregistered)
					{
						MessageBox.Show("您的账号未通过验证，请联系系统管理员。");
						return;
					}
					dlgLogin.User.IncreaseCount();
					this.CurrentUser = dlgLogin.User;
					this.cmdImportFolder();
					return;
				}
			}
			else
			{
				this.cmdImportFolder();
			}
		}

		private void cmdImportFolder()
		{
			FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
			if (this.defaultfilePath != "")
			{
				folderBrowserDialog.SelectedPath = this.defaultfilePath;
			}
			if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
			{
				this.defaultfilePath = folderBrowserDialog.SelectedPath;
				DirectoryInfo rootDir = new DirectoryInfo(folderBrowserDialog.SelectedPath);
				this.CreateCategoryByFolder(this.CurrentCategory, rootDir);
				MessageBox.Show("添加完成。", "族库管理");
				FamilyLibDatabase.FillTree(this.tvProject, this.dbs, CheckType.All);
				if (this.tvProject.Nodes[0].Nodes.Count <= 0)
				{
					this.btnLoadToPro.Enabled = false;
					return;
				}
				this.btnLoadToPro.Enabled = true;
			}
		}

		private void toolStripDropDownButton1_Click(object sender, EventArgs e)
		{
		}

		private void tsmiLogin_Click(object sender, EventArgs e)
		{
		}

		private void cmdLogout(bool showMessage = true)
		{
			this.CurrentUser = null;
			this.toolStripStatusLabel2.Text = "服务器管理账户当前未登录";
			this.tsddbCommunication.Enabled = false;
			this.tsmChangePass.Visible = false;
			this.tsLogout.Enabled = false;
			this.CurrentUser = null;
			if (showMessage)
			{
				MessageBox.Show("成功注销。");
			}
		}

		private void tsmiLogout_Click(object sender, EventArgs e)
		{
		}

		private void tsmiRegiste_Click(object sender, EventArgs e)
		{
		}

		private void tsmiChangePW_Click(object sender, EventArgs e)
		{
		}

		private void 加载ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			try
			{
				foreach (DbFamily dbFamily in this.CurrentCategory.GetAllFamilies(false, CheckType.All))
				{
					dbFamily.Load(this.m_uiApp.ActiveUIDocument.Document);
				}
				MessageBox.Show("加载完成。");
			}
			catch (Exception)
			{
				MessageBox.Show("加载异常。");
			}
		}

		private void 登陆ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.CurrentUser != null)
			{
				if (MessageBox.Show("当前已登录的账户：" + this.CurrentUser.Name + "，是否注销并更改用户登录？", "注销", MessageBoxButtons.YesNo) == DialogResult.Yes)
				{
					this.cmdLogout(true);
					this.cmdLogin();
					return;
				}
			}
			else
			{
				this.cmdLogin();
			}
		}

		private void 注册ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			new DlgRegistrate(this.mGroup).ShowDialog(this);
		}

		private void 注销ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.cmdLogout(true);
		}

		private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			new DlgChangePassword(this.CurrentUser.Name).ShowDialog(this);
		}

		private void tsddbLogin_Click(object sender, EventArgs e)
		{
		}

		private void btnDownload_Click(object sender, EventArgs e)
		{
			this.cmdDownload();
		}

		private void cmdDownload()
		{
			if (!this.IsServer)
			{
				this.doDownload();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanExport())
				{
					this.doDownload();
					return;
				}
				MessageBox.Show("您的账号没有下载族的权限。");
			}
		}

		private void doDownload()
		{
			try
			{
				SqliteDatabase sqliteDB = FamilyLibDatabase.GetSqliteDB(this.CurrentFamily.Database.SubjectTable.SubjectType, this.m_uiApp.Application.VersionNumber);
				FamilyLibDatabase.DownloadFamily(this.CurrentFamily.Database, sqliteDB, this.CurrentFamily);
				MessageBox.Show("下载成功。");
			}
			catch
			{
				MessageBox.Show("下载失败，请检查是否本地族库中已经包含此族。");
			}
		}

		private void 升级ToolStripMenuItem_Click(object sender, EventArgs e)
		{
		}

		private void toolStripDropDownButton2_Click(object sender, EventArgs e)
		{
		}

		public DbFamilySymbol DbFamilySymbo { get; set; }

		private void btnPlace_Click(object sender, EventArgs e)
		{
			if (this.dgvType.SelectedRows.Count > 0)
			{
				DataGridViewRow dataGridViewRow = this.dgvType.SelectedRows[0];
				this.DbFamilySymbo = this.CurrentFamily.Database.TypeTable[this.CurrentFamily, dataGridViewRow.Cells[1].Value.ToString()];
			}
		}

		private void 利用系数表ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (this.CurrentFamily == null || this.CurrentFamily.GetSubjectType() != SubjectType.Electric)
			{
				MessageBox.Show("请选择灯具。");
				return;
			}
			if (this.CurrentFamily.Database.CategoryTable[this.CurrentFamily.ParentId].MainCategory().Name != "灯具")
			{
				MessageBox.Show("请选择灯具。");
				return;
			}
			DatabaseType databaseType = ConfigUtils.ReadFamilyLibXmlFile("族库类型", this.m_uiApp.Application.VersionNumber).DatabaseType;
			Guid guid = this.CurrentFamily.Guid;
			string connStr = this.CurrentFamily.Database.ConnStr;
			int eid = this.CurrentFamily.ExData.Eid1;
			string utilizationFactor = UtilizationFactor.GetUtilizationFactor(databaseType, connStr, guid, ref eid);
			this.CurrentFamily.ExData.Eid1 = eid;
			this.CurrentFamily.Database.FamilyTable.Update(this.CurrentFamily);
			DataTable dataTable = this.CurrentFamily.Database.TypeTable.DataTable(this.CurrentFamily);
			if (dataTable == null)
			{
				return;
			}
			foreach (object obj in dataTable.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				try
				{
					dataRow["利用系数表"] = utilizationFactor;
				}
				catch
				{
				}
			}
			this.CurrentFamily.Database.TypeTable.Update(dataTable, this.CurrentFamily);
			this.dgvType.DataSource = dataTable;
		}

		private void 按族名查询ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgSearchByName dlgSearchByName = new DlgSearchByName(this.dbs);
			if (dlgSearchByName.ShowDialog(this) == DialogResult.OK)
			{
				this.searchName = dlgSearchByName.FamilyName;
				this.searchDb = dlgSearchByName.Database;
				this.cmdSearch(dlgSearchByName.FamilyName, dlgSearchByName.Database);
			}
		}

		private void 按日期查询ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			DlgSearchByTime dlgSearchByTime = new DlgSearchByTime(this.dbs);
			if (dlgSearchByTime.ShowDialog(this) == DialogResult.OK)
			{
				this.searchStartTime = dlgSearchByTime.StartTime;
				this.searchEndTime = dlgSearchByTime.EndTime;
				this.searchDb = dlgSearchByTime.Database;
				this.cmdSearch(dlgSearchByTime.StartTime, dlgSearchByTime.EndTime, dlgSearchByTime.Database);
			}
		}

		private void 上传利用系数表ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!this.IsServer)
			{
				this.doUploadLYXS();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanImport())
				{
					this.doUploadLYXS();
					return;
				}
				MessageBox.Show("您的账号没有上传利用系数表的权限。");
			}
		}

		private void doUploadLYXS()
		{
			try
			{
				string fileName = AssistFunc.GetAppRootPath() + "\\Data\\Config.xml";
				string dataFromConfigFile = XmlUtils.GetDataFromConfigFile(fileName, "Server", "value");
				string dataFromConfigFile2 = XmlUtils.GetDataFromConfigFile(fileName, "Uid", "value");
				string dataFromConfigFile3 = XmlUtils.GetDataFromConfigFile(fileName, "Pwd", "value");
				ConnectData cd = new ConnectData(dataFromConfigFile, dataFromConfigFile2, dataFromConfigFile3);
				FamilyLibDatabase sqliteDB = FamilyLibDatabase.GetSqliteDB(SubjectType.Electric, this.m_uiApp.Application.VersionNumber);
				FamilyLibDatabase sqlServerDB = FamilyLibDatabase.GetSqlServerDB(SubjectType.Electric, this.m_uiApp.Application.VersionNumber, cd);
				if (UtilizationFactor.DataDownloadServer(DatabaseType.Local, sqliteDB.ConnStr, DatabaseType.Server, sqlServerDB.ConnStr))
				{
					MessageBox.Show("同步成功。");
				}
				else
				{
					MessageBox.Show("同步失败。");
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void 下载利用系数表ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			if (!this.IsServer)
			{
				this.doDownloadLYXS();
				return;
			}
			if (this.CurrentUser == null)
			{
				this.cmdLogin();
			}
			if (this.CurrentUser != null)
			{
				if (this.CurrentUser.CanExport())
				{
					this.doDownloadLYXS();
					return;
				}
				MessageBox.Show("您的账号没有下载利用系数表的权限。");
			}
		}

		private void doDownloadLYXS()
		{
			try
			{
				string fileName = AssistFunc.GetAppRootPath() + "\\Data\\Config.xml";
				string dataFromConfigFile = XmlUtils.GetDataFromConfigFile(fileName, "Server", "value");
				string dataFromConfigFile2 = XmlUtils.GetDataFromConfigFile(fileName, "Uid", "value");
				string dataFromConfigFile3 = XmlUtils.GetDataFromConfigFile(fileName, "Pwd", "value");
				ConnectData cd = new ConnectData(dataFromConfigFile, dataFromConfigFile2, dataFromConfigFile3);
				FamilyLibDatabase sqliteDB = FamilyLibDatabase.GetSqliteDB(SubjectType.Electric, this.m_uiApp.Application.VersionNumber);
				FamilyLibDatabase sqlServerDB = FamilyLibDatabase.GetSqlServerDB(SubjectType.Electric, this.m_uiApp.Application.VersionNumber, cd);
				if (UtilizationFactor.DataDownloadServer(DatabaseType.Server, sqlServerDB.ConnStr, DatabaseType.Local, sqliteDB.ConnStr))
				{
					MessageBox.Show("同步成功。");
				}
				else
				{
					MessageBox.Show("同步失败。");
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void timer1_Tick(object sender, EventArgs e)
		{
			try
			{
				if (this.CurrentUser != null)
				{
					if (this.CurrentUser.NewMessageCount > 0)
					{
						this.tsddbCommunication.Text = "通讯(" + this.CurrentUser.NewMessageCount + ")";
						this.tsmiInbox.Text = "收件箱(" + this.CurrentUser.NewMessageCount + ")";
					}
					else
					{
						this.tsddbCommunication.Text = "通讯";
						this.tsmiInbox.Text = "收件箱";
					}
					this.initPermission();
				}
			}
			catch (Exception)
			{
			}
		}

		private void tsmiAddRole_Click(object sender, EventArgs e)
		{
		}

		private void tsmiRemove_Click(object sender, EventArgs e)
		{
			new DlgRemoveRole(this.mGroup).ShowDialog(this);
		}

		private void tsmiSetRight_Click(object sender, EventArgs e)
		{
			new DlgSetRight(this.mGroup).ShowDialog(this);
		}

		private void tsmiSetRole_Click(object sender, EventArgs e)
		{
			new DlgSetRole(this.mGroup).ShowDialog(this);
		}

		private void initPermission()
		{
			this.tsddbCommunication.Visible = false;
			this.tsmChangePass.Visible = true;
			this.tsddbCommunication.Visible = true;
			this.tsddbCommunication.Enabled = true;
		}

		private void tsmiSent_Click(object sender, EventArgs e)
		{
			new DlgSendMessage(this.CurrentUser).ShowDialog(this);
		}

		private void tsmiInbox_Click(object sender, EventArgs e)
		{
			new DlgMessageBox(this.CurrentUser).ShowDialog(this);
		}

		private void tsmiDelUser_Click(object sender, EventArgs e)
		{
			new DlgRemoveUser().ShowDialog(this);
		}

		private void 添加职位ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			new DlgAddRole(this.mGroup).ShowDialog(this);
		}

		private void 删除职位ToolStripMenuItem1_Click(object sender, EventArgs e)
		{
			new DlgRemoveRole(this.mGroup).ShowDialog(this);
		}

		private void 权限设置ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			new DlgSetRight(this.mGroup).ShowDialog(this);
		}

		private void tsmiVerifyUser_Click(object sender, EventArgs e)
		{
		}

		private void 删除用户ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			new DlgRemoveUser().ShowDialog(this);
		}

		private void 职位设置ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			new DlgSetRole(this.mGroup).ShowDialog(this);
		}

		private void toolStripMenuItem4_Click(object sender, EventArgs e)
		{
			new DlgSendMessage(this.CurrentUser).ShowDialog(this);
		}

		private void 收件箱ToolStripMenuItem_Click(object sender, EventArgs e)
		{
			new DlgMessageBox(this.CurrentUser).ShowDialog(this);
		}

		private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
		{
		}

		private void tvProject_AfterSelect(object sender, TreeViewEventArgs e)
		{
			this.currentFamily = null;
			TreeNode node = e.Node;
			if (node.Tag != null)
			{
				if (node.Tag is DbCategory)
				{
					this.CurrentSubject = (DbSubject)this.FindRoot(node).Tag;
					this.CurrentCategory = (DbCategory)node.Tag;
					this.CurrentFamily = null;
					return;
				}
				if (node.Tag is DbSubject)
				{
					this.CurrentSubject = (DbSubject)this.FindRoot(node).Tag;
					this.CurrentCategory = null;
					this.CurrentFamily = null;
				}
			}
		}

		private void DlgFamilyManagerForPro_FormClosing(object sender, FormClosingEventArgs e)
		{
			this.cmdLogout(false);
		}

		private static DlgFamilyManagerForPro main;

		private string mGroup = "FM";

		private UIApplication m_uiApp;

		public List<FamilyLibDatabase> dbs = new List<FamilyLibDatabase>();

		public DbSubject currentSubject;

		public DbCategory currentCategory;

		public DbFamily currentFamily;

		private bool boEdit;

		private bool boAdd;

		private ExternalCommandData mRvit;

		private FamilyLibDatabase proDb;

		public static int pageContainment = 24;

		private int pageCount;

		private int familyCount;

		private int addRowsNo;

		private SearchMode searchMode;

		private string searchName = "";

		private DateTime searchStartTime;

		private DateTime searchEndTime;

		private FamilyLibDatabase searchDb;

		private string userPath = FamilyLibDatabase.GetDefFamilyLibPath();

		private bool flag;

		private RadioButton rbTemp;

		private bool IsServer;

		private DbUser CurrentUser;

		private string defaultfilePath = "";

		public class ListViewColumnSorter : IComparer
		{
			public ListViewColumnSorter()
			{
				this.ColumnToSort = 0;
				this.OrderOfSort = SortOrder.None;
				this.ObjectCompare = new CaseInsensitiveComparer();
			}

			public int Compare(object x, object y)
			{
				return 0;
			}

			public int ColumnToSort;

			public SortOrder OrderOfSort;

			private CaseInsensitiveComparer ObjectCompare;
		}
	}
}
